package ar.edu.unicen.exa.isistan.archassis.rcs.internal;

import java.util.ArrayList;
import java.util.List;

import ar.edu.unicen.exa.isistan.archassis.rcs.RCSFileDiff;
import ar.edu.unicen.exa.isistan.archassis.rcs.RCSFileModification;

public class RCSFileDiffListFilter {
	public static <T> List<T> filter(List<T> target, RCSFileDiffListFilterPredicate<T> predicate) {
		List<T> result = new ArrayList<T>();
	    for (T element: target) {
	        if (predicate.apply(element)) {
	            result.add(element);
	        }
	    }
	    return result;
	}
	
	public static List<RCSFileDiff> filtrar(final RCSFileModification mod, List<RCSFileDiff> listFD) {
		RCSFileDiffListFilterPredicate<RCSFileDiff> isAuthorized = new RCSFileDiffListFilterPredicate<RCSFileDiff>() {
		    public boolean apply(RCSFileDiff rcsfd) {
		        // binds a boolean method in User to a reference
		        return !rcsfd.getModificationType().equals(mod);
		    }
		};
		// allUsers is a Collection<User>
		return filter(listFD, isAuthorized);
	}
}